function guid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0,
            v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}

function urlToBlob({
    name,
    url
}) {
    return new Promise(function (resolve, reject) {
        let xhr = new XMLHttpRequest();
        xhr.open("get", url, true);
        xhr.responseType = "blob";
        xhr.onload = function () {
            if (this.status == 200) {
                resolve({
                    name,
                    blob: this.response,
                });
            } else {
                reject(this); // 数据处理出错
            }
        };
        xhr.send();
    });
}

function downloadZip(files, zipName = "未命名.zip") {
    var zip = new JSZip();

    return Promise.all(files.map((i) => urlToBlob(i).then((f) => zip.file(f.name, f.blob)))).then(() => {
        zip.generateAsync({
            type: "blob"
        }).then(function (blob) {
            saveAs(blob, zipName);
        });
    });
}

function download(file) {
    urlToBlob(file).then(resp => {
        saveAs(resp.blob, file.name);
    })

}